<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/conf/global.config.php');
require_once(CONF_DIR.'db.config.php');
require_once(SRC_DIR.'util.php');

$urldata = urldecode($_SERVER['QUERY_STRING']);
parse_str($urldata, $data);

Util::Logger("notice...");
Util::Logger($urldata);

if (!isset($data['spid'],$data['server']))
{
  return_result();
}
$spid = $data['spid'];
$url = "http://58.218.207.219:82/gameback/notice.php?channel=".$spid;

Util::Logger($url);
$notice_data = json_decode(file_get_contents($url));
Util::Logger($notice_data);
$now = strtotime('now');
foreach($notice_data as $notice)
{	
	$s_time = strtotime($notice->starttime);
	$e_time = strtotime($notice->endtime);
	if ($s_time <= $now && $now <= $e_time)
	{
		return_result($notice);
		break;
	}
}

function return_result($data)
{
	$ret = -1;
	$msg = "fail";
	if ($data)
	{
		$ret = 0;
		$msg = "success";
	}
	$json = array(
		"ret" =>$ret,
		"msg" =>$msg,
		"data"=>array(
			array(
			"img_url" =>"",
			"content" =>$data->content
			)
		)
	);
	echo json_encode($json);
}

?>